package com.wondertek.poms.pre.rabbitmq.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wondertek.poms.pre.rabbitmq.pojo.MessagePojo;
import com.wondertek.poms.pre.rabbitmq.provider.MessageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gzx
 * @Date: 2020/12/27 16:47
 * @Description:
 */
@RestController
public class MessageController {

    @Autowired
    private MessageProvider provider;

    Logger logger = LoggerFactory.getLogger(MessageController.class);

    @RequestMapping(value="/send_message",produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String send_message(MessagePojo pojo){
        try {
            pojo=new MessagePojo(20,null,null);
            String json =JSONObject.toJSONString(pojo);
            pojo=new MessagePojo(20,null,json);
            provider.sendMessage(pojo);
            return JSON.toJSONString(pojo);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
